package com.z.test;

import java.util.Arrays;

public class QuickSort {

    // 快速排序
    public static void sort(int array[], int low, int high) {
        int i, j;
        int index;
        if (low >= high)
            return;
        i = low;
        j = high;
        index = array[i];
        while (i < j) {
            while (i < j && index <= array[j])
                j--;
            if (i < j)
                array[i++] = array[j];
            while (i < j && index > array[i])
                i++;
            if (i < j)
                array[j--] = array[i];
        }
        array[i] = index;
        sort(array, low, i - 1);
        sort(array, i + 1, high);
    }
    public static void main(String[] args) {
        int array[] = { 5, 8, 4, 6, 7, 1, 3, 9, 2 };
        sort(array, 0, array.length - 1);
        System.out.print(Arrays.toString(array));

    }
}